package l2ft.gameserver.ai.FakePcs;

import java.util.Collections;
import java.util.List;

import l2ft.gameserver.ai.MainFakePc;
import l2ft.gameserver.model.Skill;
import l2ft.gameserver.model.instances.NpcInstance;
import l2ft.gameserver.tables.SkillTable;

public class HealerFakePc extends MainFakePc
{
	public HealerFakePc(NpcInstance actor)
	{
		super(actor);
		defaultThinkBuff(100, 0);
	}
	
	@Override
	protected boolean thinkActive()
	{
		return defaultThinkBuff(10, 100);
	}

	@Override
	protected boolean createNewTask()
	{
		return defaultThinkBuff(10, 100);
	}

	@Override
	protected boolean defaultThinkBuff(int rateSelf, int rateFriends)
	{
		NpcInstance actor = getActor();
		if(actor.isDead())
			return true;
		
		List<NpcInstance> friends = activeFactionTargets();
		friends.add(getActor());
		//sorting targets
		Collections.sort(friends, _lowestHpComparator);
		
		for(NpcInstance npc : friends)
		{
			//leave him if he is too far
			if(npc.getDistance(getActor()) > 500)
				continue;
			double targetHp = npc.getCurrentHpPercents();
			
			//getting heal
			Skill skill;
			if(targetHp < 99)
				skill = getUsableHeal(false);
			else
				return false;
			if(skill == null)
				continue;
			//healing
			addTaskBuff(npc, skill);
			return true;
		}
		return false;
	}
	
	private Skill getUsableHeal(boolean targetMySelf)
	{
		return SkillTable.getInstance().getInfo(1218, 33);//Greater Battle Heal
	}
	
	@Override
	public int getRatePHYS()
	{
		return 25;
	}

	@Override
	public int getRateDOT()
	{
		return 40;
	}

	@Override
	public int getRateDEBUFF()
	{
		return 40;
	}

	@Override
	public int getRateDAM()
	{
		return 75;
	}

	@Override
	public int getRateSTUN()
	{
		return 10;
	}

	@Override
	public int getRateBUFF()
	{
		return 25;
	}

	@Override
	public int getRateHEAL()
	{
		return 90;
	}
}
